﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CvModel;
using DAL;

namespace LAB3_Cv
{
    public partial class Main : System.Web.UI.MasterPage
    {
        private Applicant _currentApplicant;
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["CurrentUser"] != null)
                {
                    ShowLoggedInUser();
                }
            }
        }
        private void ShowLoggedInUser()
        {
            ButtonLogout.Visible = true;
            ButtonLogin.Visible = false;
            ButtonApplied.Visible = true;
            ButtonCv.Visible = true;
            ButtonApplied.Visible = true;
            ButtonUserDetails.Visible = true;
            LoadCurrentUser();
            LabelNameLoggedIn.Visible = true;
            LabelTextLoggedIn.Visible = true;

        }

        public void LoadCurrentUser()
        {
            _currentApplicant = Session["CurrentUser"] as Applicant;
            Session["Applications"] =
                WorkApplicationsDB.GetAllWorkApplicationsFromApplicant(_currentApplicant.ApplicantId);
            LabelNameLoggedIn.Text = string.Format("{0} {1}",_currentApplicant.FirstName,_currentApplicant.LastName);
        }

        protected void Logout_ButtonLogOut(object sender, EventArgs e)
        {
            Session["SearchString"] = null;
            Session["CurrentAdmin"] = null;
            Session["AdminId"] = null;
            Session["CurrentUser"] = null;
            Session["Applications"] = null;
            Session["WorkAdId"] = null;
            Session["DeletedAd"] = null;
            Session["SelectedCv"] = null;
            Session["PrintCv"] = null;
            Session["CvList"] = null;

            ButtonLogout.Visible = false;
            ButtonLogin.Visible = true;
            ButtonApplied.Visible = false;
            ButtonCv.Visible = false;
            ButtonUserDetails.Visible = false;
            LabelNameLoggedIn.Text = "";
            LabelNameLoggedIn.Visible = false;
            LabelTextLoggedIn.Visible = false;

            Response.Redirect("~/Default.aspx");
        }

        protected void ButtonWorkAds_Click(object sender, EventArgs e)
        {

        }
    }
}